package mall

import (
	"errors"
	"github.com/jinzhu/copier"
	"mall-go-gin/global"
	"mall-go-gin/model/mall/response"
	"mall-go-gin/model/manage"
)

type MallGoodsInfoService struct {
}

// 获取商品详情
func (m *MallGoodsInfoService) GetMallGoodsInfo(id int) (err error, res response.GoodsInfoDetailResponse) {
	var mallGoodsInfo manage.MallGoodsInfo
	err = global.GVA_DB.Where("goods_id = ?", id).First(&mallGoodsInfo).Error
	if mallGoodsInfo.GoodsSellStatus != 0 {
		return errors.New("商品已下架"), response.GoodsInfoDetailResponse{}
	}
	err = copier.Copy(&res, &mallGoodsInfo)
	if err != nil {
		return err, response.GoodsInfoDetailResponse{}
	}
	var list []string
	list = append(list, mallGoodsInfo.GoodsCarousel)
	res.GoodsCarouselList = list

	return nil, res

}
